from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from presenter import editarticlepresenter
from view import baseview

class EditArticleView(baseview.BaseView):
    def get(self):
        if (not users.is_current_user_admin()):
            self.redirect('/')
        else:
            self.templatefile = "templates/editarticle.html"
            presenter = editarticlepresenter.EditArticlePresenter(request=self.request, currentuser=users.get_current_user(), view=self)
            presenter.respondToGet()

    def post(self):
        if (not users.is_current_user_admin()):
            self.redirect('/')
        else:
            presenter = editarticlepresenter.EditArticlePresenter(request=self.request, currentuser=users.get_current_user(), view=self)
            presenter.respondToPost()

    def showPostResponse(self, template_values):
        self.redirect('/adminarticle')

application = webapp.WSGIApplication(
                                     [
                                      ('/editarticle', EditArticleView)],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()